using System;
using System.Collections.Generic;
using System.Text;
using LngT.Algorithms;
using LngT.Interfaces;

namespace LngTAlgorithms
    {
    public class ShuffleIterationAlgorithm: IterationAlgorithmBase
        {
        public override IEnumerable<IItem> GetEnumerator()
            {
            if( _itemEnumerator == null || _resultEnumerator == null )
                throw new InvalidOperationException();
            List<IItem> result = new List<IItem>();
            foreach( IItem item in _itemEnumerator )
                {
                result.Add( item );
                }

            result.Sort( new Shuffler() );

            return result.AsReadOnly();
            }
        }

    class Shuffler: IComparer<IItem>
        {

        #region IComparer<IItem> Members
        Random _r = new Random();
        public int Compare( IItem x, IItem y )
            {
            return _r.Next( 3 ) - 1;
            }

        #endregion
        }
    }
